package com.otitan.la.forest.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.otitan.la.forest.system.dto.BaseParamDTO;
import com.otitan.la.forest.system.entity.BaseParamEntity;
import com.otitan.la.forest.system.service.BaseParamService;
import com.otitan.webapp.framework.basepro.model.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Description: 基础参数配置
 * @Author: jiachangsen
 * @CreateDate: 2020/10/10 10:29
 * @UpdateUser: jiachangsen
 * @UpdateDate: 2020/10/10 10:29
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Api(tags = "基础参数配置API")
@RestController
@RequestMapping("/base/param")
public class BaseParamController {

    @Autowired
    private BaseParamService baseParamService;

    @ApiOperation(value = "更新")
    @PutMapping
    public DataResult editor(@Valid @RequestBody BaseParamEntity entity, BindingResult bindingResult) {
        return baseParamService.editor(entity, bindingResult);
    }

    @ApiOperation(value = "根据ID查询")
    @GetMapping("/findOne/{id}")
    public DataResult<BaseParamEntity> findOne(@PathVariable("id") String id) {
        BaseParamEntity one = baseParamService.findOne(id);
        return DataResult.success(one);
    }

    @ApiOperation(value = "列表查询（分页）")
    @PostMapping("/findPage/{page}/{size}")
    public DataResult<Page<BaseParamEntity>> findPageData(@PathVariable("page") long page,
                                                @PathVariable("size") long size,
                                                @RequestBody BaseParamDTO dto) {
        return baseParamService.findPageData(page, size, dto);
    }
}
